/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TratamientoPanel.java
 *
 * Created on 15/08/2012, 10:54:18 PM
 */
package v;

import beans.MedicamentoDiscapacidad;
import javax.swing.DefaultComboBoxModel;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
import tools.DatosComboBox;

/**
 *
 * @author Usuario
 */
public class Medicamento_View_Add extends javax.swing.JPanel {
    
    private DatosComboBox cbx = new DatosComboBox();

    
    public Medicamento_View_Add() {
        initComponents();
        setCombos();
        AutoCompleteDecorator.decorate(medicamentoCombo);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        label1 = new javax.swing.JLabel();
        medicamentoCombo = new javax.swing.JComboBox();
        label2 = new javax.swing.JLabel();
        dosis = new javax.swing.JTextField();
        medidaCombo = new javax.swing.JComboBox();
        label3 = new javax.swing.JLabel();
        uso = new javax.swing.JTextField();
        label4 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        observaciones = new javax.swing.JTextArea();
        usoMedidaCombo = new javax.swing.JComboBox();

        label1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        label1.setText("Medicamento");

        medicamentoCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        label2.setText("Dosis");

        medidaCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        label3.setText("Uso");

        label4.setText("Observaciones");

        observaciones.setColumns(20);
        observaciones.setLineWrap(true);
        observaciones.setRows(5);
        jScrollPane1.setViewportView(observaciones);

        usoMedidaCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label1)
                    .addComponent(label2)
                    .addComponent(label3)
                    .addComponent(label4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 207, Short.MAX_VALUE)
                    .addComponent(medicamentoCombo, 0, 207, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(uso, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(dosis, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 36, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(usoMedidaCombo, 0, 1, Short.MAX_VALUE)
                            .addComponent(medidaCombo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label1)
                    .addComponent(medicamentoCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label2)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(dosis, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(medidaCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(uso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label3)
                    .addComponent(usoMedidaCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label4)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField dosis;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel label1;
    private javax.swing.JLabel label2;
    private javax.swing.JLabel label3;
    private javax.swing.JLabel label4;
    private javax.swing.JComboBox medicamentoCombo;
    private javax.swing.JComboBox medidaCombo;
    private javax.swing.JTextArea observaciones;
    private javax.swing.JTextField uso;
    private javax.swing.JComboBox usoMedidaCombo;
    // End of variables declaration//GEN-END:variables

    private void setCombos() {
        medicamentoCombo.setModel(new DefaultComboBoxModel(cbx.cbMedicamentos()));
        medicamentoCombo.setSelectedIndex(0);
        
        medidaCombo.setModel(new DefaultComboBoxModel(cbx.cbMedidaTiempo()));
        medidaCombo.setSelectedIndex(0);
        
        usoMedidaCombo.setModel(new DefaultComboBoxModel(cbx.cbMedidaTiempo()));
        usoMedidaCombo.setSelectedIndex(0);
    }
    
    public MedicamentoDiscapacidad getInfo() throws Exception{
        MedicamentoDiscapacidad result = new MedicamentoDiscapacidad();
        
//        String selectedItem = medicamentoCombo.getSelectedItem().toString();
        Integer idMed = Integer.valueOf(cbx.getKeyMedicamentos(medicamentoCombo));
        result.setIdMedicamento(idMed);
        
        String dosisVal = dosis.getText();
        try{
            Integer valor = Integer.parseInt(dosisVal);
            result.setDosis(valor);
        }catch(NumberFormatException e){
            throw new Exception("Digite un número valido en Dosis");
        }
        
//        String med = medidaCombo.getSelectedItem().toString();
        Integer idMedida = Integer.valueOf(cbx.getKeyMedida(medidaCombo));
        result.setDosisMedidaTiempo(idMedida);
        
        String usoVal = uso.getText();
        try{
            Integer valor = Integer.parseInt(usoVal);
            result.setUso(valor);
        }catch(NumberFormatException e){
            throw new Exception("Digite un número valido en Uso");
        }
        Integer idUsoMedida = Integer.valueOf(cbx.getKeyMedida(usoMedidaCombo));
        result.setUsoMedidaTiempo(idUsoMedida);
        
        
        String observ = observaciones.getText();
        result.setObservacion(observ);
        
        return result;
    }
    
    public void resetearComponentes(){
        medicamentoCombo.setSelectedIndex(0);
        dosis.setText("");
        medidaCombo.setSelectedIndex(0);
        uso.setText("");
        usoMedidaCombo.setSelectedIndex(0);
        observaciones.setText("");
    }
}
